package com.hiquety.tcb.disk;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.hiquety.tcb.config.AppInfo;
import com.hiquety.tcb.entity.ClipboardItem;
import com.hiquety.tcb.ui.IndexUI;
import org.apache.commons.io.FileUtils;

import java.util.List;

public class ClipboardItemDisk {

    public static List<ClipboardItem> read() {
        try {
            String s = FileUtils.readFileToString(AppInfo.CLIPBOARD_FILE, "utf-8");
            List<ClipboardItem> list = JSONArray.parseArray(s, ClipboardItem.class);
            if (list != null) {
                return list;
            }
        } catch (Exception e) {
        }
        return null;
    }

    public static void write() {
        try {
            String s = JSON.toJSONString(IndexUI.observableList);
            FileUtils.write(AppInfo.CLIPBOARD_FILE, s, "utf-8");
        } catch (Exception e) {
        }
    }
}
